package com.parking.carsystem.parkingchargesystem.utils;


import android.app.Activity;
import android.widget.TextView;

import com.parking.carsystem.parkingchargesystem.view.time.ConvertUtils;
import com.parking.carsystem.parkingchargesystem.view.time.DatePicker;
import com.parking.carsystem.parkingchargesystem.view.time.DateTimePicker;

import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;

public class TimeUtil {
    private final static String TIME_FORMAT = "HH:mm";
    private final static String TIME_FORMAT_YMDHMS = "yyyy-MM-dd HH:mm:ss";
    private final static String TIME_FORMAT_YMDHM = "yyyy-MM-dd HH:mm";
    private final static String TIME_FORMAT_MDHMS = "MM-dd HH:mm:ss";
    private final static String TIME_FORMAT_YMD = "yyyy-MM-dd";

    private final static String TIME_FORMAT_YMD_2 = "yyyyMMdd";

    /**
     * 将时间显示为HH:mm:SS,注意HH不是24小时制也不是12小时制，是累计的小时数，
     * 可能是大于24，此方法主要用于播放器界面的时间显示
     *
     * @param millisecond 时间毫秒
     * @return HH:mm:SS
     */
    public static String formatForPlayer(long millisecond) {
        DecimalFormat df = new DecimalFormat("00");
        StringBuilder timeString = new StringBuilder();
        long hour = millisecond / (1000 * 60 * 60);
        long minute = millisecond % (1000 * 60 * 60) / (1000 * 60);
        long second = millisecond % (1000 * 60) / 1000;
        timeString.append(df.format(hour)).append(":");
        timeString.append(df.format(minute)).append(":")
                .append(df.format(second));
        return timeString.toString();
    }

    /**
     * 获取当前时间的小时和分钟
     *
     * @return HH:mm
     */
    public static String getCurFormatTime() {
        SimpleDateFormat df = new SimpleDateFormat(TIME_FORMAT, Locale.CHINA);
        return df.format(new Date());
    }

    /**
     * 获取当前时间的yyyy-MM-dd HH:mm:ss格式
     *
     * @return yyyy-MM-dd HH:mm:ss
     */
    public static String getCurYMDTime() {
        SimpleDateFormat df = new SimpleDateFormat(TIME_FORMAT_YMDHMS, Locale.CHINA);
        return df.format(new Date());
    }

    public static String getCurYMDFTime() {
        SimpleDateFormat df = new SimpleDateFormat(TIME_FORMAT_YMDHMS, Locale.CHINA);
        return df.format(new Date());
    }

    //获取上一天的时间
    public static String getYesTody() {
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.DATE, -1); //向前走一天
        SimpleDateFormat df = new SimpleDateFormat(TIME_FORMAT_YMDHMS, Locale.CHINA);
        return df.format(calendar.getTime());
    }

    public static String getNextMounth(){
        Calendar cal = Calendar.getInstance();//获取一个Calendar对象
        cal.add(Calendar.MONTH, 1);//获取当前时间的下一个月
        SimpleDateFormat df = new SimpleDateFormat(TIME_FORMAT_YMD, Locale.CHINA);
        return df.format(cal.getTime());
    }
    /**
     * 将yyyy-MM-dd HH:mm:ss格式的时间转变为MM-dd HH:mm:ss
     *
     * @param dateString 时间字符串
     * @return 转变后的值
     */
    public static String formatToMDHms(String dateString) {
        String result = "";
        Date date = getDateFromString(dateString);
        if (date != null) {
            result = getDateStringMdHms(date);
        }
        return result;
    }

    /**
     * 将yyyy-MM-dd HH:mm:ss格式的时间转变为HH:mm
     *
     * @param dateString 时间字符串
     * @return 转变后的值
     */
    public static String formatToHm(String dateString) {
        String result = "";
        Date date = getDateFromString(dateString);
        if (date != null) {
            result = getDateStringHm(date);
        }
        return result;
    }

    /**
     * 将yyyy-MM-dd HH:mm:ss格式的时间转变为Date类型
     *
     * @param dateString 时间字符串
     * @return 转变后的值
     */
    public static Date getDateFromString(String dateString) {
        SimpleDateFormat df = new SimpleDateFormat(TIME_FORMAT_YMDHMS, Locale.CHINA);
        Date date = null;
        try {
            date = df.parse(dateString);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date;
    }

    /**
     * 将"yyyy-MM-dd HH:mm:ss"格式的日期转为long类型的time
     *
     * @param timeString 时间字符串
     * @return long类型的time
     */
    public static long getCommonTime(String timeString) {
        SimpleDateFormat sdf = new SimpleDateFormat(TIME_FORMAT_YMDHMS, Locale.CHINA);
        try {
            Date d = sdf.parse(timeString);
            return d.getTime();
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return 0;
    }

    /**
     * 获取昨天的时间的 0点的毫秒值
     *
     * @return
     */
    public static long getTimeOfWeekStart() {
        Calendar ca = Calendar.getInstance();
        ca.set(Calendar.HOUR_OF_DAY, 0);
        ca.clear(Calendar.MINUTE);
        ca.clear(Calendar.SECOND);
        ca.clear(Calendar.MILLISECOND);
        ca.roll(Calendar.DAY_OF_YEAR, -1);
        return ca.getTimeInMillis();
    }

    /**
     * 将"yyyy-MM-dd HH:mm:ss"格式的日期转为"yyyy-MM-dd"格式
     *
     * @param timeString 时间字符串
     * @return long类型的time
     */
    public static String formatDateStr(String timeString) {
        SimpleDateFormat sdfBefore = new SimpleDateFormat(TIME_FORMAT_YMDHMS, Locale.CHINA);
        SimpleDateFormat sdfAfter = new SimpleDateFormat(TIME_FORMAT_YMD, Locale.CHINA);
        try {
            return sdfAfter.format(sdfBefore.parse(timeString));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return "";
    }


    /**
     * 将"yyyy-MM-dd格式的日期转为long类型的time
     *
     * @param timeString 时间字符串
     * @return long类型的time
     */
    public static long getYMDCommonTime(String timeString) {
        SimpleDateFormat sdf = new SimpleDateFormat(TIME_FORMAT_YMD, Locale.CHINA);
        try {
            Date d = sdf.parse(timeString);
            return d.getTime();
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return 0;
    }

    public static long getHoursLong() {
        String curFormatTime = getCurFormatTime();
        SimpleDateFormat sdf = new SimpleDateFormat(TIME_FORMAT, Locale.CHINA);
        try {
            Date d = sdf.parse(curFormatTime);
            return d.getTime();
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return 0;
    }

    public static long getYearHoursLong() {
        String curFormatTime = getCurYMDFTime();
        SimpleDateFormat sdf = new SimpleDateFormat(TIME_FORMAT_YMDHMS, Locale.CHINA);
        try {
            Date d = sdf.parse(curFormatTime);
            return d.getTime();
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return 0;
    }

    /**
     * 将日期转换为yyyy-MM-dd HH:mm:ss格式字符串
     *
     * @param date 日期
     * @return yyyy-MM-dd HH:mm:ss
     */
    public static String getDateString(Date date) {
        SimpleDateFormat sdf = new SimpleDateFormat(TIME_FORMAT_YMDHMS, Locale.CHINA);
        return sdf.format(date);
    }

    /**
     * 将日期转换为MM-dd HH:mm:ss格式字符串
     *
     * @param date 日期
     * @return MM-dd HH:mm:ss
     */
    public static String getDateStringMdHms(Date date) {
        SimpleDateFormat sdf = new SimpleDateFormat(TIME_FORMAT_MDHMS, Locale.CHINA);
        return sdf.format(date);
    }

    /**
     * 将日期转换为HH:mm格式字符串
     *
     * @param date 日期
     * @return HH:mm
     */
    public static String getDateStringHm(Date date) {
        SimpleDateFormat sdf = new SimpleDateFormat(TIME_FORMAT, Locale.CHINA);
        return sdf.format(date);
    }

    /**
     * 将日期转换为yyyy-MM-dd格式字符串
     *
     * @return yyyy-MM-dd
     */
    public static String getYMDString() {
        SimpleDateFormat sdf = new SimpleDateFormat(TIME_FORMAT_YMD, Locale.CHINA);
        return sdf.format(new Date());
    }

    /**
     * 将日期转换为yyyy-MM-dd格式字符串
     *
     * @param date 日期
     * @return yyyyMMdd
     */
    public static String getYMDString2(Date date) {
        SimpleDateFormat sdf = new SimpleDateFormat(TIME_FORMAT_YMD_2, Locale.CHINA);
        return sdf.format(date);
    }

    /**
     * 得到某年某月的第一天
     */
    public static String getFirstDayOfMonth(int year, int month) {
        Calendar cal = Calendar.getInstance();
        cal.set(Calendar.YEAR, year);
        cal.set(Calendar.MONTH, month - 1);
        cal.set(Calendar.DAY_OF_MONTH, cal.getMinimum(Calendar.DATE));
        return new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA).format(cal.getTime());
    }

    /**
     * 得到某年某月的最后一天
     */
    public static String getLastDayOfMonth(int year, int month) {
        Calendar cal = Calendar.getInstance();
        cal.set(Calendar.YEAR, year);
        cal.set(Calendar.MONTH, month - 1);
        cal.set(Calendar.DAY_OF_MONTH, 1);
        int value = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
        cal.set(Calendar.DAY_OF_MONTH, value);
        return new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA).format(cal.getTime());
    }


    public static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

    public static String getDate(long time) {
        String times = "";
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        times = sdf.format(time);
        return times;
    }

    public static String getTimeVideo(long time) {
        String times = "";
        SimpleDateFormat sdf = new SimpleDateFormat("dd HH:mm:ss");
        times = sdf.format(time);
        return times;
    }

    public static String getDateDay(long time) {
        String times = "";
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        times = sdf.format(time);
        return times;
    }

    public static Calendar StringToCalendar(String time) {
        Date date = null;
        Calendar calendar = null;
        try {
            date = sdf.parse(time);
            calendar = Calendar.getInstance();
            calendar.setTime(date);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return calendar;

    }

    public static Calendar LongToCalendar(long time) {
        Date date = null;
        Calendar calendar = null;
        try {
            date = new Date(time);
            calendar = Calendar.getInstance();
            calendar.setTime(date);
            calendar.add(calendar.MONTH, -3);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return calendar;

    }

    public static int getDistanceMonth(String date1, String date2) {
        int distance = 0;
        int distanceTime = 0;
        Calendar calendar1 = Calendar.getInstance();
        Calendar calendar2 = Calendar.getInstance();
        try {
            calendar1.setTime(sdf.parse(date1));
            calendar2.setTime(sdf.parse(date2));
            distance = calendar2.get(Calendar.MONTH) - calendar1.get(Calendar.MONTH);
            distanceTime = calendar2.get(Calendar.DAY_OF_MONTH) - calendar1.get(Calendar.DAY_OF_MONTH);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        if (distance == 3 && distanceTime > 0)
            distance = 4;
        return distance;
    }

    /**
     * 获取两个时间点之间的时间间隔
     *
     * @param date1 第一个时间点
     * @param date2 第二个时间点
     * @return 时间间隔
     */
    public static String getDistanceTime(String date1, String date2) {
        SimpleDateFormat sdf = new SimpleDateFormat(TIME_FORMAT_YMDHMS);
        try {
            long time1 = sdf.parse(date1).getTime();
            long time2 = sdf.parse(date2).getTime();

            int second = (int) ((time2 - time1) / 1000);
            return getVideoLength(second);
        } catch (ParseException e) {
            e.printStackTrace();
            return "0";
        }
    }

    /**
     * 获取两个时间点之间的时间间隔
     *
     * @param date1 第一个时间点
     * @param date2 第二个时间点
     * @return 时间间隔
     */
    public static boolean chatDistanceTime(String date1, String date2) {
        SimpleDateFormat sdf = new SimpleDateFormat(TIME_FORMAT_YMDHMS);
        try {
            long time1 = sdf.parse(date1).getTime();
            long time2 = sdf.parse(date2).getTime();
            int second;
            if (time1 >= time2) {
                second = (int) ((time1 - time2) / 1000);
            } else {
                second = (int) ((time2 - time1) / 1000);
            }
            return getChatLength(second);
        } catch (ParseException e) {
            e.printStackTrace();
            return false;
        }
    }

    /**
     * 获取下一天的0点0分0秒
     *
     * @return
     */
    private Date getTimeOf12() {
        Calendar cal = Calendar.getInstance();
        cal.setTime(new Date());
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);
        cal.add(Calendar.DAY_OF_MONTH, 1);
        return cal.getTime();
    }

    /**
     * 今天的0点0分0秒
     *
     * @return
     */
    public static long getTodayZero() {
        Date date = new Date();
        long l = 24 * 60 * 60 * 1000; //每天的毫秒数
        //date.getTime()是现在的毫秒数，它 减去 当天零点到现在的毫秒数（ 现在的毫秒数%一天总的毫秒数，取余。），理论上等于零点的毫秒数，不过这个毫秒数是UTC+0时区的。
        //减8个小时的毫秒值是为了解决时区的问题。
        return (date.getTime() - (date.getTime() % l) - 8 * 60 * 60 * 1000);
    }

    /**
     * 今天的0点0分0秒
     *
     * @return
     */
    public static long getYesTodayZero() {
        Date date = new Date();
        long l = 24 * 60 * 60 * 1000; //每天的毫秒数
        //date.getTime()是现在的毫秒数，它 减去 当天零点到现在的毫秒数（ 现在的毫秒数%2天总的毫秒数，取余。），理论上等于零点的毫秒数，不过这个毫秒数是UTC+0时区的。
        //减8个小时的毫秒值是为了解决时区的问题。
        return (date.getTime() - (date.getTime() % 2) - 8 * 60 * 60 * 1000);
    }

    /**
     * 获取格式化之后的视频时间长度
     *
     * @return 视频时间
     */
    public static boolean getChatLength(int videoSecond) {

        int hour = 0;
        int minute = 0;
        int second = 0;

        if (videoSecond > 0) {
            hour = videoSecond / (60 * 60);
            minute = (videoSecond - hour * 60 * 60) / 60;
            second = videoSecond % 60;
        }
        if (Integer.parseInt(formatChatTimeUnite(hour)) > 0) {
            return true;
        }
        return Integer.parseInt(formatChatTimeUnite(minute)) >= 2;
    }

    /**
     * 格式化时间组成单元
     *
     * @param num 时间
     * @return 格式化后的时间
     */
    private static String formatChatTimeUnite(int num) {
        if (num > 9) {
            return String.valueOf(num);
        } else {
            return String.valueOf(num);
        }
    }

    /**
     * 获取两个时间点之间的时间间隔
     *
     * @param date1 第一个时间点
     * @param date2 第二个时间点
     * @return 时间间隔
     */
    public static String getDistanceTextTime(String date1, String date2) {
        SimpleDateFormat sdf = new SimpleDateFormat(TIME_FORMAT_YMDHMS);
        try {
            long time1 = sdf.parse(date1).getTime();
            long time2 = sdf.parse(date2).getTime();

            int second = (int) ((time2 - time1) / 1000);
            return getVideoTextLength(second);
        } catch (ParseException e) {
            e.printStackTrace();
            return "0";
        }
    }

    /**
     * 获取两个时间点之间的时间间隔
     *
     * @param date1 第一个时间点
     * @param date2 第二个时间点
     * @return 时间间隔 获取实际的时间间隔
     */
    public static int startDistanceTime(String date1, String date2) {
        SimpleDateFormat sdf = new SimpleDateFormat(TIME_FORMAT_YMDHMS);
        try {
            long time1 = sdf.parse(date1).getTime();
            long time2 = sdf.parse(date2).getTime();

            int second = (int) ((time2 - time1) / 1000);
            return second;
        } catch (ParseException e) {
            e.printStackTrace();
            return 0;
        }
    }
    /**
     * 获取两个时间点之间的时间间隔
     *
     * @param date1 第一个时间点
     * @param date2 第二个时间点
     * @return 时间间隔 获取实际的时间间隔
     */
    public static int getTimeDay(String date1, String date2) {
        SimpleDateFormat sdf = new SimpleDateFormat(TIME_FORMAT_YMD);
        try {
            long time1 = sdf.parse(date1).getTime();
            long time2 = sdf.parse(date2).getTime();

            int day = (int) ((time2 - time1) /(60*60*1000*24));
            return day;
        } catch (ParseException e) {
            e.printStackTrace();
            return 0;
        }
    }
    /**
     * 获取格式化之后的视频时间长度
     *
     * @return 视频时间
     */
    public static String getVideoTextLength(int videoSecond) {

        int hour = 0;
        int minute = 0;
        int second = 0;

        if (videoSecond > 0) {
            hour = videoSecond / (60 * 60);
            minute = (videoSecond - hour * 60 * 60) / 60;
            second = videoSecond % 60;
        }
        int time_hour = Integer.parseInt(formatTimeUnite(hour));
        int time_minute = Integer.parseInt(formatTimeUnite(minute));
        int time_second = Integer.parseInt(formatTimeUnite(second));
        if (time_hour > 0) {
            return time_hour + "小时" + time_minute + "分钟" + time_second + "秒";
        }
        if (time_minute > 0) {
            return time_minute + "分钟" + time_second + "秒";
        }
        if (time_second > 0) {
            return time_second + "秒";
        }
        return "0";
    }

    public static String getDistanceTime(long date2) {
        int timeLong = (int) (date2 * 1000);
        int hour = new Long(timeLong / (1000 * 60 * 60)).intValue();
        int tempLeft_minute = new Long(timeLong % (1000 * 60 * 60))
                .intValue();
        int minute = new Long(tempLeft_minute / (1000 * 60)).intValue();
        int tempLeft_second = new Long(tempLeft_minute % (1000 * 60))
                .intValue();
        int second = new Long(tempLeft_second / 1000).intValue();

        StringBuilder sb = new StringBuilder();
        if (hour > 0) {
            if (hour > 9)
                sb.append(hour + ":");
            else
                sb.append("0" + hour + ":");
        } else {
            sb.append("00:");
        }

        if (minute > 0) {
            if (minute > 9)
                sb.append(minute + ":");
            else
                sb.append("0" + minute + ":");
        } else {
            sb.append("00:");
        }

        if (second > 0) {
            if (second > 9)
                sb.append(second + "");
            else
                sb.append("0" + second + "");
        } else {
            sb.append("00:");
        }

        return sb.toString();
    }

    public static String formatForPlayerTime(long date2) {
        int timeLong = (int) (date2 * 1000);
//        int hour = new Long(timeLong / (1000 * 60 * 60)).intValue();
        int tempLeft_minute = new Long(timeLong % (1000 * 60 * 60))
                .intValue();
        int minute = new Long(tempLeft_minute / (1000 * 60)).intValue();
        int tempLeft_second = new Long(tempLeft_minute % (1000 * 60))
                .intValue();
        int second = new Long(tempLeft_second / 1000).intValue();

        StringBuilder sb = new StringBuilder();
//        if (hour > 0) {
//            if (hour > 9)
//                sb.append(hour + ":");
//            else
//                sb.append("0" + hour + ":");
//        } else {
//            sb.append("00:");
//        }

        if (minute > 0) {
            if (minute > 9)
                sb.append(minute + ":");
            else
                sb.append("0" + minute + ":");
        } else {
            sb.append("00:");
        }

        if (second > 0) {
            if (second > 9)
                sb.append(second + "");
            else
                sb.append("0" + second + "");
        } else {
            sb.append("00");
        }

        return sb.toString();
    }

    public static Calendar getCurrentCalendar() {
        Calendar calendar = Calendar.getInstance();
        return calendar;
    }


    /**
     * 获取格式化之后的视频时间长度
     *
     * @return 视频时间
     */
    public static String getVideoLength(int videoSecond) {

        int hour = 0;
        int minute = 0;
        int second = 0;

        if (videoSecond > 0) {
            hour = videoSecond / (60 * 60);
            minute = (videoSecond - hour * 60 * 60) / 60;
            second = videoSecond % 60;
        }

        return formatTimeUnite(hour) + ":" + formatTimeUnite(minute) + ":" + formatTimeUnite(second);
    }

    /**
     * 格式化时间组成单元
     *
     * @param num 时间
     * @return 格式化后的时间
     */
    private static String formatTimeUnite(int num) {
        if (num > 9) {
            return String.valueOf(num);
        } else {
            return "0" + num;
        }
    }

    /**
     * 转换成计时时间 00：00：00
     *
     * @param ttime
     * @return
     */
    public static String timeCalculate(long ttime) {
        long daysuuu, hoursuuu, minutesuuu, secondsuuu;
        String daysT = "", restT = "";
        daysuuu = (Math.round(ttime) / 86400);
        hoursuuu = (Math.round(ttime) / 3600) - (daysuuu * 24);
        minutesuuu = (Math.round(ttime) / 60) - (daysuuu * 1440) - (hoursuuu * 60);
        secondsuuu = Math.round(ttime) % 60;
        if (daysuuu == 1) daysT = String.format("%d day ", daysuuu);
        if (daysuuu > 1) daysT = String.format("%d days ", daysuuu);
        restT = String.format("%02d:%02d:%02d", hoursuuu, minutesuuu, secondsuuu);
        return daysT + restT;
    }

    /**
     * java获取指定日期所在周的第一天和最后一天
     *
     * @param dataStr
     * @return
     * @throws ParseException
     */
    public static String getFirstAndLastOfWeek(String dataStr) throws ParseException {
        Calendar cal = Calendar.getInstance();

        cal.setTime(new SimpleDateFormat("yyyy-MM-dd").parse(dataStr));

        int d = 0;
        if (cal.get(Calendar.DAY_OF_WEEK) == 1) {
            d = -6;
        } else {
            d = 2 - cal.get(Calendar.DAY_OF_WEEK);
        }
        cal.add(Calendar.DAY_OF_WEEK, d);
        // 所在周开始日期
        String data1 = new SimpleDateFormat("yyyy/MM/dd").format(cal.getTime());
        cal.add(Calendar.DAY_OF_WEEK, 6);
        // 所在周结束日期
        String data2 = new SimpleDateFormat("yyyy/MM/dd").format(cal.getTime());
        return data1 + "-" + data2;

    }
    public static void chooseStartTime(final TextView time_start, Activity mActivity) {
        // https://github.com/gzu-liyujiang/AndroidPicker 地址链接
        DateTimePicker picker = new DateTimePicker(mActivity, DateTimePicker.HOUR_24);
        picker.setDateRangeStart(2017, 1, 1);
        picker.setDateRangeEnd(2025, 11, 11);
//        picker.setTimeRangeStart(0, 0);
//        picker.setTimeRangeEnd(23, 59);
        picker.setOnDateTimePickListener(new DateTimePicker.OnYearMonthDayTimePickListener() {
            @Override
            public void onDateTimePicked(String year, String month, String day, String hour, String minute) {
                time_start.setText(year + "-" + month + "-" + day + " " + hour + ":" + minute);
//                long startCommonTime = TimeUtil.getCommonTime((String) time_start.getText());
//                long endCommonTime = TimeUtil.getCommonTime((String) time_end.getText());
//                if (endCommonTime < startCommonTime) {
//                    Toast.makeText(mActivity, "时间格式错误,请重新选择", Toast.LENGTH_SHORT).show();
//                    time_start.setText(TimeUtil.getYesTody(getDate()));
//                } else {
//                    Toast.makeText(mActivity, year + "-" + month + "-" + day + " " + hour + ":" + minute + ":00", Toast.LENGTH_SHORT).show();
//                }
            }
        });
        picker.show();
    }
    public static void chooseonYearMonthDayPicker(final TextView time_start, Activity mActivity) {
        final DatePicker picker = new DatePicker(mActivity);
        picker.setCanceledOnTouchOutside(true);
        picker.setUseWeight(true);
        picker.setTopPadding(ConvertUtils.toPx(mActivity, 10));
        picker.setRangeEnd(2111, 1, 11);
        picker.setRangeStart(2016, 8, 29);
        picker.setSelectedItem(2020, 10, 14);
        picker.setResetWhileWheel(false);
        picker.setOnDatePickListener(new DatePicker.OnYearMonthDayPickListener() {
            @Override
            public void onDatePicked(String year, String month, String day) {
                time_start.setText(year + "-" + month + "-" + day);
            }
        });
        picker.setOnWheelListener(new DatePicker.OnWheelListener() {
            @Override
            public void onYearWheeled(int index, String year) {
                picker.setTitleText(year + "-" + picker.getSelectedMonth() + "-" + picker.getSelectedDay());
            }

            @Override
            public void onMonthWheeled(int index, String month) {
                picker.setTitleText(picker.getSelectedYear() + "-" + month + "-" + picker.getSelectedDay());
            }

            @Override
            public void onDayWheeled(int index, String day) {
                picker.setTitleText(picker.getSelectedYear() + "-" + picker.getSelectedMonth() + "-" + day);
            }
        });
        picker.show();
    }
}

